<!--
 * @Author: zhanbh
 * @Date: 2021-04-13 15:03:58
 * @project: 天津YQ平台
-->
<template>
  <module-tabs class="yq-sign" v-model="activeName" :tabs="tabs" is-flex-box>
    <template #first>
      <sign :other-form="otherForm" ref="form" :source-data="signData"/>
    </template>
    <template #second>
      <add ref="add" modify :source-type="sourceType" v-if="sourceType" :flow-id="flowId"/>
    </template>
    <template #header-btns>
      <dg-button type="primary" size="mini" :loading="loading" @click="onSubmit">提交</dg-button>
      <dg-button size="mini" @click="() => $router.go(-1)">关闭</dg-button>
    </template>
  </module-tabs>
</template>

<script>
import ModuleTabs from '@/components/layout/module-tabs';
import Sign from '../components/Sign';
import Add from '@/pages/ExterCommun/add';
import { flowMainSignIn,getFlowDetail } from '@/api/common';
export default {
  name: 'ImpSign',
  components: {
    ModuleTabs,
    Add,
    Sign
  },
  props: {
    otherForm: {
      type: Function,
      default: (vm) => {
        return () => {
          let textareaAttrs = {
            type: 'textarea',
            rows: 3,
            placeholder: '请输入内容',
            maxLength: 200
          };
          return [
            {
              prop: 'cbyj',
              label: '呈报意见',
              tag: 'el-input',
              tagBind: textareaAttrs
            },
            {
              prop: 'xxbs',
              label: '信息报送',
              tag: 'el-input',
              tagBind: textareaAttrs
            },
            {
              prop: 'nxdzl',
              label: '拟下达指令',
              tag: 'el-input',
              tagBind: textareaAttrs
            },
            {
              prop: 'drzsCode',
              label: '当日值守',
              col: 12,

              tag: 'dg-select',
              tagBind: {
                data: vm.jrzs,
                valueName: 'id',
                labelName: 'name'
              }
            },
            {
              prop: 'drzhzCode',
              label: '今日指挥长',
              col: 12,
              tag: 'dg-select',
              tagBind: {
                data: vm.djrzs,
                valueName: 'id',
                labelName: 'name'
              }
            }
          ];
        };
      }
    }
  },
  computed: {
    flowId() {
      return this.$route.params.id;
    }
  },
  data() {
    return {
      sourceType:'',
      loading:false,
      tabs: [
        {
          label: '签收',
          name: 'first'
        },
        {
          label: '基本信息',
          name: 'second'
        }
      ],
      activeName: 'first',
      signData: {} // 签收数据
    };
  },
created(){
  this.getFlowDetail()
},
  methods: {
    getFlowDetail(){
      getFlowDetail(this.flowId).then(({data})=>{
        this.sourceType=data.sourceType;
        this.signData = data.signInVO; // 初始化签收信息
      })
    },
    onSubmit() {
      let that_ = this;
      this.$refs.form.$refs.form.$refs.form.validate((valid) => {
        if (valid) {
          that_.loading = true;
          flowMainSignIn({
            id: that_.signData && that_.signData.id ? that_.signData.id : '',
            flowId: that_.flowId,
            ...that_.$refs.form.form
          })
            .then(() => {
              that_.$message.success('签收成功');
              that_.$refs.add.addExterCommun();
              that_.loading = false;
            })
            .catch((err) => {
              console.log(err);
              that_.$message.warning('操作失败');
              that_.loading = false;
            });
        }
      });
    }
  }
};
</script>

<style lang="scss" scoped>
.yq-sign {
  height: calc(100vh - 11rem);

  &__group {
    display: flex;
    align-items: center;

    .dg-radio {
      margin-left: 0.5rem;
    }
  }
}
.edit-form {
  max-width: 1000px;
}
</style>
